package com.gutsyzhan.dynamicdatasourcespringbootstarter.datasource;

import org.springframework.jdbc.datasource.AbstractDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public abstract class AbstractRoutingDataSource extends AbstractDataSource {
    @Override
    public Connection getConnection() throws SQLException {
        return determinateDataSource().getConnection();
    }

    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        return determinateDataSource().getConnection(username, password);
    }

    /**
     * 通过子类来获取具体的数据源
     */
    protected abstract DataSource determinateDataSource();
}
